# Contributor: Sui Libin <bygreencn@gmail.com>

_realname=vlfeat
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.21
pkgrel=3
pkgdesc="The VLFeat open source library implements popular computer vision algorithms specializing in image understanding and local features extraction and matching. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=(BSD)
url="https://www.vlfeat.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("https://www.vlfeat.org/download/${_realname}-${pkgver}.tar.gz"
        "01-vlfeat-0.9.20-1-buildsys.mingw.patch"
        "02-Makefile-fix-arch-detection.patch"
        "03-fix-openmp-building-with-gcc.patch"
        "04-remove-fpic-rpath-for-clang.patch")
sha256sums=('8cbf686fd008e3d119c3a0986ffd06e4c3d9448b6f4721a9cc9bb4964c82ff55'
            'ff1b998d5af23bcd3e0e5f4084d1d29a67e08c0b0a8c2f36829ad435278ffd5f'
            'b377ccec0b9934720111b1bed0afc420dd244747df80cd358ed92afc2c5d0d61'
            '84151ec314d5b63fee45eb91ac7c9a1181fb4361d41f40fc1707763c1ce5e55a'
            'afe3ff1fb934d768cf3dc7c5f498b2acc05f80d56194ca5653c1ef1bb3789f0e')

prepare() {
  # Replace minizip with external
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/01-vlfeat-0.9.20-1-buildsys.mingw.patch"
  patch -p1 -i "${srcdir}/02-Makefile-fix-arch-detection.patch"

  # https://github.com/vlfeat/vlfeat/pull/200.patch
  patch -p1 -i "${srcdir}/03-fix-openmp-building-with-gcc.patch"

  patch -p1 -i "${srcdir}/04-remove-fpic-rpath-for-clang.patch"
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  make all
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make DESTDIR="${pkgdir}" prefix=${MINGW_PREFIX} install
}
